package com.baichang.taoshunda.utils;

import com.baichang.framework.Constant;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

/**
 * Ueditor图片自定义标签
 * Created by Dylan on 2015/11/2.
 */
public class UeditorImageTag extends SimpleTagSupport {

    private String content;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public void doTag() throws JspException, IOException {

        Document document =  Jsoup.parse(content);
        Elements imgs = document.select("img");
        for(int i=0;i<imgs.size();i++){
            Element img = imgs.get(i);
            String url = Constant.ueditorVisitUrl+img.attr("src");
            img.attr("src",url);
            img.attr("width","100%");
        }
        content=document.body().html();
        getJspContext().getOut().println(content);
    }
}
